﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using Edge.Common.Utils;
using Edge.Business.Entities;
using Iesi.Collections.Generic;
using Edge.Common;
using Edge.Common.ComponentModel;
using Edge.Common.DataUtils;

namespace Dune.Business.Domain.Users
{
    #region Users

    /// <summary>
    /// Users object for NHibernate mapped table 'users'.
    /// </summary>
    [Serializable]
    public class User : UserEntity<int>
    {
        public const int UNSAVED_ID = -1;

        #region Member Variables

        protected UserType _type;
        protected DateTime _birthday;
        protected string imageSrc;
        protected int invitesNumber = 3;
        protected ICollection<Person> persons;


        public virtual ICollection<Person> Persons
        {
            get { return persons; }
            set { persons = value; }
        }

        public virtual DateTime Birthday
        {
            get { return _birthday; }
            set { _birthday = value; }
        }

        #endregion

        #region Constructors

        public User()
        {
            Id = UNSAVED_ID;
        }

        public User(string passwrd, string e_mail, DateTime registerDate, UserType type)
        {
            Id = UNSAVED_ID;
            this._passwrd = passwrd;
            this._email = e_mail;
            this.CreateDate = registerDate;
            this._type = type;
        }

        #endregion

        #region Public Properties

        [Browsable(true),
            Order(3),
            Description("Last Name"),
            DesignerScope(DesignerScope.EditView | DesignerScope.Create)]
       public virtual int InvitesNumber
        {
            get { return invitesNumber; }
            set { invitesNumber = value; }
        }
       

        [Browsable(true),
            Order(9),
            Description("Last update"),
            ReadOnly(true),
            DesignerScope(DesignerScope.View)]
        public virtual string ImageSrc
        {
            get { return imageSrc; }
            set { imageSrc = value; }
        }

        [Browsable(true),
            Description("Type"),
            Order(13),
            ReadOnly(true),
            DesignerScope(DesignerScope.EditView | DesignerScope.Create)]
        public virtual UserType Type
        {
            get { return _type; }
            set { _type = value; }
        }


        public static ICollection<T> Find<T>(string text, ICollection<T> source)
            where T : User
        {
            if (StringUtils.IsBlankOrNull(text))
                return source;
            return CollectionsUtils.FindAll<T>(source, delegate(T a)
                                                                 {
                                                                     return
                                                                         StringUtils.Contains(text.Trim(), a.Email);
                                                                 });
        }
    }

    #endregion
    #endregion


}
